{extend name="base" /}
{block name="body"}
<div class="layui-body">
    <!--tab标签-->
    <div class="layui-tab layui-tab-brief">
        <ul class="layui-tab-title">
            <li class="layui-this">机器人管理</li>
            <li class=""><a href="{:url('admin/robot/add')}">添加机器人</a></li>
        </ul>
        <div class="layui-tab-content">
            <div class="layui-tab-item layui-show">

                <form class="layui-form layui-form-pane" action="{:url('admin/robot/index')}" method="get">
                    <div class="layui-inline">
                        <label class="layui-form-label">关键词</label>
                        <div class="layui-input-inline">
                            <input type="text" name="keyword" value="{$keyword}" placeholder="请输入关键词" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button class="layui-btn">搜索</button>
                    </div>

                    <br>

                    <div class="layui-form-item">
                        <label class="layui-form-label">是否启用</label>
                        <div class="layui-input-block">
                            <input type="checkbox" name="status" lay-filter="status" lay-skin="switch" {if condition="$robot_status.value == '1'"} checked {/if}>
                        </div>
                    </div>
                </form>
                <hr>

                <table class="layui-table">
                    <thead>
                    <tr>
                        <th style="width: 30px;">ID</th>
                        <th>头像</th>
                        <th>用户名</th>
                        <th>UUID</th>
                        <th>昵称</th>
                        <th>创建时间</th>
                        <th>所在房间</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach name="user_list" item="vo"}
                    <tr>
                        <td>{$vo.id}</td>
                        <td><img src="{$vo.headimg}"  style="width:32px;height:32px;"/></td>
                        <td>{$vo.username}</td>
                        <td>{$vo.user_uuid}</td>
                        <td>{$vo.user_nick}</td>
                        <td>{$vo.create_time}</td>
                        <td>
                            {if condition="$vo.room_uuid"}
                            <a href="{:url('admin/room/robot',['id' => $vo['room_id']])}" class="layui-btn layui-btn-mini">{$vo.room_uuid}</a></td>
                        {/if}
                        <td>
                            <a href="{:url('admin/robot/edit',['id'=>$vo['id']])}" class="layui-btn layui-btn-normal layui-btn-mini">编辑</a>
                            <a href="{:url('admin/robot/delete',['id'=>$vo['id']])}" class="layui-btn layui-btn-danger layui-btn-mini ajax-delete">删除</a>
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                </table>
                <!--分页-->
                {$user_list->render()}
            </div>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script>
    $('.mc-ajax').click(function(e){
        e.preventDefault();
        var _action = $(this).attr('href');
        layer.prompt({
            formType: 0,
            value: '0',
            title: '输入增减的数量',
            // area: ['200px', '350px'] //自定义文本域宽高
        }, function(value, index, elem){
            console.log(parseFloat(value))
            if(!value.trim() || !isNaN(parseFloat(value.trim())) == 0){
                layer.msg('请输入大于0的数字');
                return false;
            }
            $.ajax({
                url: _action,
                data: {amount:value},
                success: function (info) {
                    if (info.code === 1) {
                        setTimeout(function () {
                            location.reload()
                        }, 1000);
                    }
                    layer.msg(info.msg);
                }
            });
            // alert(value); //得到value
            layer.close(index);
        });
    });

    form.on('switch(status)', function(data){
        // console.log(data.elem); //得到checkbox原始DOM对象
        // console.log(data.elem.checked); //开关是否开启，true或者false
        // console.log(data.value); //开关value值，也可以通过data.elem.value得到
        // console.log(data.othis); //得到美化后的DOM对象

        $.post('{:url("admin/robot/changeRobotStatus")}',{state:data.elem.checked},function(res){
            layer.msg(res.msg);
        },'json');
    });
</script>
{/block}